package leetcode;

/**
 * @author Europa
 */
public class Num1614 {

    public int maxDepth(String s) {
        if(s.length() == 1) {
            return 0;
        }
        int depth = 0, left = 0;
        // 字符串拆成数组
        char[] chars = s.toCharArray();
        for (char c : chars) {
            //
            switch (c) {
                case '(':
                    // 遇到(就+1
                    left++;
                    if (left > depth) {
                        depth = left;
                    }
                    break;
                case ')':
                    // 遇到)就-1
                    left--;
                    break;
                default:
            }
        }
        return depth;
    }

    public static void main(String[] args) {
        Num1614 num1614 = new Num1614();
        String str = "(1+(2*3)+((8)/4))+1";
        int i = num1614.maxDepth(str);
        System.out.println(i);
    }
}
